﻿//--------通过18位报关单号抓取通关状态-----------
//---------创建人：曾同春 ------------------
//---------创建时间：2016-06-08  ------------------

var casper = require('casper').create();
//报关单号
var applyNo = casper.cli.get('applyNo').replace("'", "").replace("'", "");
casper.start('http://www.haiguan.info/OnLineSearch/Gateway/weixin/weixinGatewaystate.html');

casper.then(function () {
    var cookies = this.page.cookies;
    var checkcode = cookies[0].value;
    this.evaluate(function (applyNo, code) {
        //document.querySelector('input[id="stateCode"]').setAttribute('value', company);
        //document.querySelector('input[id="verifyCode"]').setAttribute('value', code);
        document.querySelector('input[id="stateCode"]').setAttribute('value', applyNo);
        document.querySelector('input[id="verifyCode"]').setAttribute('value', code);
    }, applyNo, checkcode);
    this.click('#search');
});


//casper.thenEvaluate(function (term) {
    
//    document.querySelector('input[id="stateCode"]').setAttribute('value', term);
//    document.querySelector('input[id="verifyCode"]').setAttribute('value', code);
//}, applyNo);

//casper.then(function() {
//    // Click on 1st result link
//    this.click('#search');
////console.log(this.getHTML());
//});
casper.waitForSelector("table", function () {
    console.log(this.getHTML());
});

//casper.then(function() {
//   console.log(this.getHTML());
//});

casper.run();